//
//  AXMyFormerYearsDiseaseVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/10.
//  Copyright © 2018 tzhg. All rights reserved.
//
//往年病害
#import "AXMyFormerYearsDiseaseVC.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "Header.h"
#import "UIViewController+HBD.h"
#import "AXMyFormerYearsDiseaseCell.h"
#import "AXMyFormerYearsDiseaseModel.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "BaoxianListSelectView.h"

@interface AXMyFormerYearsDiseaseVC ()<UITableViewDelegate,UITableViewDataSource,GHWBaoxianlistSelectDelegate>

@property (nonatomic , strong) NSMutableArray<AXMyFormerYearsDiseaseModel *> *modelsArray;

@property (nonatomic ,strong) UITableView *tableView;





@end

@implementation AXMyFormerYearsDiseaseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self setupNavigationItems];
    [self creatView];
    [self setlayout];
    
   

}

- (void)selectFirst:(NSArray*)first and:(NSArray*)second
{
    
    __block NSString * str = @"";
    [first enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        str = [NSString stringWithFormat:@"%@、%@",str,first[idx]];
    }];
    [second enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        str = [NSString stringWithFormat:@"%@、%@",str,second[idx]];
    }];
    //_contentLb.text = str;
    
}

- (void)creatView {
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    //注册cell
    
    [self.tableView registerClass:[AXMyFormerYearsDiseaseCell class] forCellReuseIdentifier:[AXMyFormerYearsDiseaseCell reuseID]];
    ;
  
    ;
    
    [self.view addSubview:self.tableView];
    
    
}

- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, Hs)
    .widthIs(Wi)
    .heightIs(TableViewHeight);
    
    
    
}

#pragma mark -action




//自定义UIBarButtonItem
- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    
    //返回按钮
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.titleLabel.font = FONT_FOURTEEN;
    [rightBtn setTitleColor:COLOR_DIV forState:UIControlStateNormal];
    [rightBtn setTitle:@"新增" forState:UIControlStateNormal];
    rightBtn.frame = CGRectMake(0, 0, 30, 30);
    [rightBtn addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
    /** 搜索 */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"添加作物";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
    
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)add:(UIButton *)btn {
  
    /** 导航条白色 */
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    
    BaoxianListSelectView *baoxianselectView2 = [[BaoxianListSelectView alloc]initViewWithTitles:@[@"     选泽病害"] andImages:@[@[@"霜煤病1",@"霜煤病2",@"霜煤病3",@"霜煤病4",@"霜煤病5",@"霜煤病6",@"霜煤病7",@"霜煤病8",@"霜煤病9",@"霜煤病10",@"霜煤病11",@"霜煤病12",@"霜煤病13",@"霜煤病14",@"霜煤病15",@"霜煤病16",@"霜煤病17"]]];
    baoxianselectView2.ghwbaoxianselectdelegate = self;
    [baoxianselectView2 show];
    
}


#pragma mark - action



#pragma mark - tableViewDelegate & tableViewDatasorce


//分区头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
    view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    return view;
    
    
}
/** 分区的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    return 10;
    
}


//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
  
    return 1;
    
}

/** cell的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    return 44;
    
     return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[AXMyFormerYearsDiseaseCell class] contentViewWidth:SCREEN_WIDTH];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
   
   
    
    AXMyFormerYearsDiseaseCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyFormerYearsDiseaseCell  reuseID] forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  
    return cell;
    
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}



@end

